package com.summer.data.jql.table;

import com.summer.data.Jql;
import com.summer.data.Jsql;
import com.summer.data.dialect.Dialect;
import com.summer.data.jql.behavior.TableAble;
import com.summer.data.jql.concept.Field;
import com.summer.data.table.BaseColumn;

/**
 * @author 345480567@qq.com
 */
public class JqlTable extends TableAble {

    Jql jql;

    public JqlTable(Jql jql) {
        this.jql = jql;
    }

    @Override
    public Jsql getTableSql(Dialect dialect) {
        return Jsql.format("(%s)", jql.buildJsql(dialect));
    }

    public Field<?> field(String fieldName) {
        return new NamedJqlColumn<>(this, fieldName);
    }

    public <T> Field<T> field(String fieldName, Class<T> clazz) {
        return new NamedJqlColumn<>(this, fieldName, clazz);
    }

    public NamedJqlStringColumn strField(String fieldName) {
        return new NamedJqlStringColumn(this, fieldName);
    }

    public <T> Field<T> field(BaseColumn<T> column) {
        return new ColumnedJqlColumn<>(this, column);
    }

}
